package com.itheima.controller;

import com.itheima.bean.Account;
import com.itheima.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 测试请求参数的绑定奶
 */
@Controller
@RequestMapping("/param")
public class ParamController {

    /**
     * 请求参数的绑定
     * @param username
     * @param password
     * @return
     */
    @RequestMapping("/testParam")
    public String testParam(String username,String password) {
        System.out.println("执行了。。。。。。");
        System.out.println("用户名："+username);
        System.out.println("密码："+password);
        return "success";
    }

    /**
     * 请求参数的绑定把数据封装到javabean的类中
     * @param account
     * @return
     */
    @RequestMapping(value = "/saveAccount",method = RequestMethod.POST)
    public String saveAccount(Account account) {
        System.out.println("执行了。。。。。。");
        System.out.println("用户："+account);
        return "success";
    }


    /**
     * 自定义类型转换
     * @param user
     * @return
     */
    @RequestMapping(value = "/saveUser",method = RequestMethod.POST)
    public String saveUser(User user) {
        System.out.println("执行了。。。。。。");
        System.out.println("用户："+user);
        return "success";
    }

    /**
     * 原生API测试
     * @return
     */
    @RequestMapping(value = "/testServlet")
    public String testServlet(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("执行了。。。。。。");
        System.out.println(request);
        HttpSession session = request.getSession();
        System.out.println(session);
        ServletContext servletContext = session.getServletContext();
        System.out.println(servletContext);
        return "success";
    }

}
